<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>转正申请</title>
    <script src="../../../../../res/js/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="../../../../../res/js/login_common.js" charset="utf-8"></script>
    <script src="../../../../../res/layui/layui.js" charset="utf-8"></script>
    <script src="../../../../../res/js/Tools.js" charset="utf-8"></script>
    <link rel="shortcut icon" type="image/x-icon" href="../../../../../res/images/favicon.ico">
    <link rel="stylesheet" href="../../../../../res/layui/css/layui.css" media="all">
</head>
<body style="padding: 10px">
<div style="display: none" id="bodys">
    <form action="" class="layui-form layui-form-pane" lay-filter="example">
        <h1 align="center" style="margin-bottom: 20px">员工转正薪资定级表</h1>
        <!--流程id-->
        <input name="pkRegularId" id="pkRegularId" type="hidden"/>
        <!--流程进度-->
        <input name="isRevision" id="isRevision" type="hidden"/>
        <!--员工id-->
        <input name="personnelId" id="personnelId" type="hidden"/>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">员工工号</label>
                <div class="layui-input-inline">
                    <input autocomplete="off" class="layui-input" name="employeeNumber"
                           id="employeeNumber" placeholder="请输入工号（必填）" disabled=""
                           type="text"/>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-inline">
                    <input autocomplete="off" class="layui-input" lay-verify="required" name="personnelName"
                           id="personnelName" placeholder="请输入名字（必填）" disabled=""
                           type="text"/>
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">入职日期</label>
                <div class="layui-input-inline">
                    <input autocomplete="off" class="layui-input" id="affirmTime" lay-verify="date"
                           name="affirmTime"
                           placeholder="yyyy-MM-dd（必填）"
                           type="text">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">部门</label>
                <div class="layui-input-inline">
                    <input autocomplete="off" class="layui-input" lay-verify="required" id="departmentName"
                           name="departmentName" placeholder="请输入部门（必填）" disabled=""
                           type="text"/>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">岗位</label>
                <div class="layui-input-inline">
                    <input autocomplete="off" class="layui-input" lay-verify="required" id="postName"
                           name="postName" placeholder="请输入岗位（必填）" disabled=""
                           type="text"/>
                </div>
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">公司《薪资保密条款》</label>
            <div class="layui-input-block">
            <textarea placeholder="请输入内容" class="layui-textarea" disabled="">
                1、员工薪酬属于个人隐私和公司秘密，在任何场合、任何情况下，每个员工不得对内、对外泄露本人已经公司的薪资福利待遇的具体细节和具体金额。严格禁止打听、议论、对比他人的工资。
                2、凡本公司员工，如有透露本人或他人工资的行为，公司将给予警告、记过等行政处分及经济处罚，情节严重的，同时，公司还将保留进一步的追究相应法律责任。
            </textarea>
                <input type="checkbox" name="consent" id="consent" lay-skin="primary" title="本人已完全知晓以上相关内容，特此确认！">
            </div>
        </div>

        <!-- 提交-->
        <div class="layui-form-item" id="sub">
            <div class="layui-input-block" id="flows">
                <button type="submit" class="layui-btn site-demo-active" lay-submit="" lay-filter="demo1">立即提交</button>
            </div>
        </div>
    </form>

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend>流程日志</legend>
    </fieldset>
    <ul class="layui-timeline" id="schedule">

    </ul>
</div>
<script>
    let pkRegularId = getQueryString("pkRegularId");
    layui.use(['form', 'laydate', 'table'], function () {
        var table = layui.table;
        var form = layui.form
            , layer = layui.layer
            , laydate = layui.laydate;

        //入职日期
        laydate.render({
            elem: '#affirmTime'
        });

        let res;
        if (pkRegularId) {
            res = getAjaxById(getRootPath() + "OaRegularFlowAction/findById/" + pkRegularId);
        }else{
            res =  getAjaxById(getRootPath() + "OaPersonnelAction/getUser");
        }
        let data=getAjaxById(getRootPath()+"OaRegularFlowAction/isExist");
        if(data){
            //墨绿深蓝风
            layer.alert('你已提交转正申请请勿重复提交', {
                skin: 'layui-layer-molv' //样式类名
                ,closeBtn: 0
            }, function(){
                formClose();
                parent.layui.table.reload('test');//刷新父页面
                const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
            });
        }

        if (res) {
            console.info(res);
            // 员工名称
            $("#personnelName").val(res.personnelName);
            // 员工工号
            $("#employeeNumber").val(res.employeeNumber);
            // 员工id
            $("#personnelId").val(res.pkPersonnelId);

            // 查询入职时间
            let data = getAjaxById(getRootPath()+"oaEntryFlowAction/findByPersonnelId");
            if(data){
                $("#affirmTime").val(dateFormat('yyyy-MM-dd', new Date(data.affirmTime)));
            }
            // 部门
            $("#departmentName").val(res.departmentName);
            // 岗位
            $("#postName").val(res.postName);
            /*// 查询部门
            if(res.organizationType){
                data = getAjaxById(getRootPath()+"OaDepartmentAction/findById/"+res.organizationId);
                if(data.data){
                    $("#departmentName").val(data.data.departmentName);
                }
            }

            // 查询岗位
            if(res.organizationId){
                data = getAjaxById(getRootPath()+"OaOrganizationAction/selectById/"+res.organizationType);
                if(data.data){


                    $("#postName").val(data.data.postName);
                }
            }*/
            form.render();
        }


        //监听起草提交
        form.on('submit(demo1)', function (data) {

            if (!$("#consent").prop("checked")) {
                layer.alert("请同意：公司《薪资保密条款》", {
                    title: '提示'
                });
                return false;
            }

            console.info(data.field);
            data={
                affirmTime:$("#affirmTime").val(),
                personnelId:$("#personnelId").val()
            };
            // 单击之后提交按钮不可选,防止重复提交
            var DISABLED = 'layui-btn-disabled';
            // 增加样式
            $('.site-demo-active').addClass(DISABLED);
            // 增加属性
            $('.site-demo-active').attr('disabled', 'disabled');
            const res = postAjax(getRootPath() + "OaRegularFlowAction/add", data);
            if (res.code === 1) {
                layer.msg('新增成功3秒后关闭当前窗口', {icon: 1});
                setTimeout(function () {
                    formClose();
                }, 3000);
                setTimeout(function () {
                    parent.layui.table.reload('test');//刷新父页面
                    //window.parent.location.reload();//刷新父页面
                    const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);
                }, 3000);
                //window.location.reload();//刷新页面
            } else if (res.code === 500) {
                error('500');
            } else {
                layer.msg("新增失败");
            }
            return false;
        });

        if(pkRegularId){
            const ress = getAjaxById(getRootPath() + "OaFlowAction/selectFlowSchedule/" + $("#pkRegularId").val());
            $("#schedule").html("");
            $.each(ress, function (index, item) {
                if (item.createdBy) {
                    $("#schedule").append('<li class="layui-timeline-item">\n' +
                        '        <i class="layui-icon layui-timeline-axis"></i>\n' +
                        '        <div class="layui-timeline-content layui-text">\n' +
                        '            <h3 class="layui-timeline-title">' + dateFormat('yyyy-MM-dd hh:mm:ss', new Date(item.createdTime)) + '&nbsp;&nbsp;&nbsp;' + item.flowName + '</h3>\n' +
                        '            <p>' + item.formReason + '</p>\n' +
                        '            <p>操作人：' + item.createdBy + '</p>\n' +
                        '        </div>\n' +
                        '    </li>')

                } else {
                    $("#schedule").append('<li class="layui-timeline-item">\n' +
                        '        <i class="layui-icon layui-timeline-axis"></ i>\n' +
                        '        <div class="layui-timeline-content layui-text">\n' +
                        '            <h3 class="layui-timeline-title">' + dateFormat('yyyy-MM-dd hh:mm:ss', new Date(item.createdTime)) + '&nbsp;&nbsp;&nbsp;' + item.flowName + '</h3>\n' +
                        '            <p>' + item.formReason + '</p>\n' +
                        '        </div>\n' +
                        '    </li>')
                }
            });
        }


        if (isButton("ENTRY_CHECK") && $("#isRevision").val() === "L") {
            $("#entryCheck").show();
            $("#trialDate").attr("lay-verify", "required");
            $("#trialMoney").attr("lay-verify", "required");
            $("#officialMoney").attr("lay-verify", "required");
        }
        $("#bodys").show();
        form.render();
    });
</script>
</body>
</html>